<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <#include "/common/base.html" >
    <script>

    </script>
</head>
<body class="easyui-layout" style="min-width: 615px;">
    <div data-options="region:'center',fit: true, border: false">
        <div id="user-auth-panel" class="easyui-panel" data-options="fit:'true',border: false" style="padding: 20px;position: relative;left: 30px;">
            <div style="width: 260px;float: left;">
                已拥有的权限1：<br>
            <select id="hasAuth" multiple="multiple" style="width: 200px;height: 260px;">
                <#list has as auth>
                    <option value="${auth.id}">${auth.name}</option>
                </#list>
            </select>
            </div>
            <div style="width: 100px;margin-top: 86px;left: 230px;float: left;">
                <a href="#" class="easyui-linkbutton" onclick="addAuth()">==></a>
                <a href="#" class="easyui-linkbutton" style="top: 78px;position: relative;left: -50px;" onclick="removeAuth()"><==</a>
            </div>
            <div style="width: 260px;float: left;">
                不具有的权限2：<br>
            <select id="noAuth" multiple="multiple" style="width: 200px;height: 260px;">
                <#list no as auth>
                    <option value="${auth.id}">${auth.name}</option>
                </#list>
            </select>
            </div>
            <p style="position: fixed;top: 310px;left: 47px;">
            <button onclick="saveAuth()" id="save-btn">保存权限</button>
        </div>
    </div>
</body>
<script>
    var $USER_WIN = null;
    $(function () {
        $USER_WIN = $('#user-auth-panel');
    })
    function addAuth(){
        var hasAuth = $('#hasAuth option:selected');
        hasAuth.each(function(a,b,c){
            var v = $(b).val();
            var t = $(b).text();
            removeRecord('hasAuth', v, t);
            addRecord('noAuth', v, t);
        })
    }
    function removeAuth(){
        var noAuth = $('#noAuth option:selected');
        noAuth.each(function(a,b,c){
            var v = $(b).val();
            var t = $(b).text();
            removeRecord('noAuth', v, t);
            addRecord('hasAuth', v, t);
        })
    }
    function removeRecord(selectId, v) {
        $('#'+selectId+' option[value='+v+']').remove();
    }
    function addRecord(selectId, v, t) {
        $('#'+selectId).append('<option value='+v+'>'+t+'</option>');
    }
    function saveAuth(){
        $('#save-btn').attr('disabled', true);
        art.dialog({
            content: '确定要修改权限吗？',
            ok: function () {
                loading();
                confirmAuth();
            },
            cancel: function(){
                $('#save-btn').attr('disabled', false);
            },
            cancelVal: '关闭'
        });
    }

    function confirmAuth(){
        var checkdIds = [];
        var hasAuth = $('#hasAuth option');
        hasAuth.each(function(a,b,c){
            var v = $(b).val();
            checkdIds.push(v);
        });
        var secRows = parentGetSelections();
        var userId = secRows[0]['id'];
        $.ajax({
            url: 'ls/modifyTransferAuth',
            type: 'post',
            data: {payeeMerIds: checkdIds.join(','), roleId: userId},
            success: function(rsp){
                $('#save-btn').attr('disabled', false);
                if(rsp['success']){
                    msg('操作成功', true);
                }else {
                    msg(rsp['info'],true);
                }
                closeTopLoading();
            },
            error: function(){
                closeTopLoading();
                $('#save-btn').attr('disabled', false);
                msg('操作出错',true);
        }
        });
    }
</script>
</html>